$(document).ready(function () {
 		var arr = get();
		for(var i=0; i<arr.length;i++){
			$("#change").append("<option value="+arr[i].id+">"+arr[i].sortName+"</option>");
		}			
			
});

//添加商户类型
function add() {
	//获得地区信息
	var userId=getvl("userId");
	var sortTypeId = $("#change").val();
    $.ajax({
        url:  urlcore + "/api/sortBetween/addShopSortBetween?userId="+userId+"&sortTypeId="+sortTypeId,
       		type: "post",
			dataType: 'json',
			contentType: "application/json;charset=utf-8",
			success:function(data){
				if (data.success == true) {             
                    if (confirm("添加成功，是否继续添加？")) {
                        //刷新
                        location.reload();
                    } else {
                        //跳转列表页
                        window.location.href = "shop_details.html?id="+userId;
                    }	                   
                }
             else if (data.code == 'OVERTIME') {
                var thisUrl = window.location.href;
                if (thisUrl.indexOf('login.html') <= -1) {
                    top.window.location.href = "login.html";
                }
            } else {
                alert(data.msg);
            }

        },
        error: function() {
            alert("error");
        }

    });
}

function get(){
	var da='';
	$.ajax({
            url: urlcore + "/api/sortType/findAllShop",
            type: "get",
            dataType: 'json',
            contentType: "application/json;charset=utf-8",
            async: false,
            success:function(data){
                if (data.success == true) {
                    da = data.data;                   
	                /* $('#messUrl').html(imgStr2);                  
                    $('#title').text(da.title);
                    $('#content').html(da.content);*/
                } else if (data.code == 'OVERTIME'){
                    var thisUrl = window.location.href;
                    if (thisUrl.indexOf('login.html') <= -1) {
                        top.window.location.href="login.html";
                    }
                } else {
                    alert(data.msg);
                }
            },
            error:function() {
                /* Act on the event */
                alert("error");
            }
        });
        return da;
}
